﻿using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _02数组
{
    class Program
    {
        static void Main(string[] args)
        {
            #region         //声明方式1
            /*
            int size = 12;
            //声明方式
            int[] monthArr = new int[size];
            //访问方式
            //访问数组的每一个元素
            for(int i=0;i<monthArr.Length;i++)
            {
                monthArr[i] = i * 10;
                //Console.WriteLine(monthArr[0]);
            }
            //另一种访问方式
            //只读遍历,不能在循环中修改数值
            foreach (int number in monthArr)
            {
                Console.WriteLine(monthArr[number]); 
            }
            */
            #endregion
            #region //声明方式2
            /*
            int[] bymonthDayArr = new int [] { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
            //访问数组元素
            foreach (var daynumber in bymonthDayArr)
            {
                Console.WriteLine(daynumber);
            }
            *//*
            Console.WriteLine("请输入年/月/日");
            string str = Console.ReadLine();
            char[] separtor = { '/' };
            string[] strArr = str.Split(separtor);
            int theYear = int.Parse(strArr[0]);//年
            int theMonth = int.Parse(strArr[1]);//月
            int theDay = int.Parse(strArr[2]);//日
            int[] month = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
            int[] day = new int[] { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
            int sum = 0;
            for (int counter=1;counter<=theMonth;counter++)
            {
                sum += month[counter];
            }
            sum += theDay;
                        if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)&&year>3)
            {
                Console.WriteLine("是闰年");
                sum += 1;
            }
            Console.WriteLine("这是一年中的第{0}天", sum);
            }
            */
            #endregion
            #region//二维数组
            //声明并初始化
            int[,] nineBoxArr = new int[3, 3] { 
                { 4, 9, 2 }, 
                { 3, 5, 7 }, 
                { 8, 1, 6 } 
            };
            //Console.WriteLine(nineBoxArr[0,0] + nineBoxArr[0,1] + nineBoxArr[0,2]);
            for(int i=0;i<3;i++)
            {
                for (int j = 0; j < 3; j++)
                    Console.Write(nineBoxArr[i, j] + "  ");
                Console.WriteLine();
            }
            #endregion
        }
    }
}